// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-12-21

#ifndef __MSVR_USER_H_SERVER_SVR_MAIN__
#define __MSVR_USER_H_SERVER_SVR_MAIN__

#pragma once

#include <common/svr_base/svr_user.h>
#include <common/svr_base/svr_userset.h>
#include "msvr_room.h"

namespace JoyServer
{

class CJoyMainServer;
class CJoyTransmitData;
class CJoyTransTCPSocket;

class CJoyMainUser : public CJoyUser
{
protected:
    virtual void OnKick();

public:
    // network messages.
    virtual void NetMsg_Recv(const JoyMessage::MessageBase* msg);
    virtual void OnNetMsg_MainLogin(const JoyMessage::MC_MainLogin* msg);
    virtual void OnNetMsg_Logout(const JoyMessage::MC_Logout* msg);
    virtual void OnNetMsg_UserStatus(const JoyMessage::MC_UserStatus* msg);
    virtual void OnNetMsg_Chat(const JoyMessage::MC_Chat* msg);

	// added by lr 2005-04-29
	virtual void OnNetMsg_CSTrench(const JoyMessage::MC_CSTrench *msg);

    virtual void OnNetMsg_SockTransmitUDP(const JoyMessage::MC_SockTransmitUDP* msg);
    virtual void OnNetMsg_SockTransmitTCP(const JoyMessage::MC_SockTransmitTCP* msg);
    virtual void OnNetMsg_SockAccept(const JoyMessage::MC_SockAccept* msg);
    virtual void OnNetMsg_SockConnect(const JoyMessage::MC_SockConnect* msg);
    virtual void OnNetMsg_SockClose(const JoyMessage::MC_SockClose* msg);

	virtual void OnNetMsg_ReLogin(const JoyMessage::MC_ReMainLogin* msg);

public:
    typedef CJoyMainRoom::CDummyIPSlot  CDummyIpSlot;
    typedef CJoyMainRoom::CUserRoomData CUserRoomData;

    CDummyIpSlot*   m_dummyIPSlot;
    CUserRoomData*  m_roomData;
    CJoyMainRoom*   m_room;

    DWORD   m_lastChat;
    UINT    m_credit;
    int     m_networkSpeed;
    bool    m_playing;
    bool    m_inRoom;

    // troop attributes.
    bool    m_troop_banned;
    bool    m_troop_command;
    bool    m_troop_chat;
    bool    m_troop_kickUser;
    bool    m_troop_muteUser;
    bool    m_troop_blockUser;
    bool    m_troop_changeRoomPass;
    bool    m_troop_closeRoom;
    bool    m_troop_sendNote;

    // transmit datas.
    sockaddr_in m_udpAddr;
    CJoyTransTCPSocket* m_tcpSock;
public:
    CJoyMainUser();
    virtual ~CJoyMainUser();

    CJoyMainServer* GetServer()
    {
        return (CJoyMainServer*)m_userSet->m_server;
    }

    void SendNote(PCSTR pszText, int nTextLen = -1);
    void FillUserInfo(JoyMessage::UserInfo& info);
    void SendUserInfo();
    int GetDummyIP();

    void TransSendUDP(CJoyTransmitData* pData);
    void TransSendTCP(CJoyTransmitData* pData);
    void TransSendTCP(const JoyMessage::MessageBase* msg);
};


} // namespace JoyServer

#endif  // __MSVR_USER_H_SERVER_SVR_MAIN__
